package com.agricultural.robot.model;

/**
 * 收割机 - 具体农机类型
 */
public class Harvester extends AgriculturalMachine {
    private double cuttingHeight;
    private double collectedCrop;

    public Harvester(String name) {
        super(name);
        this.cuttingHeight = 10.0; // 默认切割高度(厘米)
        this.collectedCrop = 0.0; // 初始收集量(千克)
    }

    public double getCuttingHeight() {
        return cuttingHeight;
    }

    public void setCuttingHeight(double cuttingHeight) {
        this.cuttingHeight = cuttingHeight;
        System.out.println(getName() + " 切割高度调整为: " + cuttingHeight + "厘米");
    }

    public double getCollectedCrop() {
        return collectedCrop;
    }

    public void setCollectedCrop(double collectedCrop) {
        this.collectedCrop = collectedCrop;
        System.out.println(getName() + " 收集量更新为: " + collectedCrop + "千克");
    }

    @Override
    public void performTask(Task task) {
        if (task instanceof HarvestingTask) {
            HarvestingTask harvestingTask = (HarvestingTask) task;
            System.out.println(getName() + " 开始执行收割任务: " + harvestingTask.getCropType() + " 在 " + harvestingTask.getFieldArea());
            System.out.println("切割高度: " + cuttingHeight + "厘米");
            consumeBattery(15.0);
            setCollectedCrop(collectedCrop + 50.0);
        } else {
            System.out.println(getName() + " 无法执行该类型任务: " + task.getClass().getSimpleName());
        }
    }

    @Override
    public void update(EnvironmentData data) {
        super.update(data);
        // 根据作物生长状态调整切割高度
        if ("成熟".equals(data.getCropGrowthStatus())) {
            setCuttingHeight(cuttingHeight * 0.9); // 成熟作物降低切割高度
        } else if ("未成熟".equals(data.getCropGrowthStatus())) {
            setCuttingHeight(cuttingHeight * 1.1); // 未成熟作物提高切割高度
        }
    }
}
